package com.orderVideo.utils;

import com.orderVideo.entity.User;
import com.orderVideo.exception.BusinessException;

public class LoginUser {
    private static final ThreadLocal<User> userHolder = new ThreadLocal<>();

    public static void setUser(User user) {
        userHolder.set(user);
    }

    public static User getUser() {
        return userHolder.get();
    }

    public static Long getUserId() {
        User user = getUser();
        if (user == null){
            throw new BusinessException("用户未登录");
        }

        return user.getUserId();
    }

    public static void remove() {
        userHolder.remove();
    }
} 